package com.maximporges.riatest;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;

public class ExecutionWrapper
{
   private InputStream inputStream;
   private OutputStream outputStream;
   private Integration integration;

   public ExecutionWrapper()
   {
      this(null, null, null);
   }
   
   public ExecutionWrapper(InputStream inputStream, OutputStream outputStream, Integration integration)
   {
      setInputStream(inputStream);
      setOutputStream(outputStream);
      setIntegration(integration);
   }
   
   public void execute() throws Exception
   {
      String input;
      BufferedReader inputStream = new BufferedReader(new InputStreamReader(getInputStream()));
      while ((input = inputStream.readLine()) != null)
      {
         PrintWriter output = new PrintWriter(getOutputStream());
         output.print(integration.execute(input));
         output.flush();
      }
   }
   
   public InputStream getInputStream()
   {
      return inputStream;
   }

   public void setInputStream(InputStream inputStream)
   {
      this.inputStream = inputStream;
   }

   public OutputStream getOutputStream()
   {
      return outputStream;
   }

   public void setOutputStream(OutputStream outputStream)
   {
      this.outputStream = outputStream;
   }

   public Integration getIntegration()
   {
      return integration;
   }

   public void setIntegration(Integration integration)
   {
      this.integration = integration;
   }
}
